home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / editors / emacs / emacs-19.000 / emacs-19 / usr / local / info / emacs-2 < prev    next >
Encoding:
GNU Info File  |  1995-09-11  |  47.0 KB  |  1,041 lines

  1. This is Info file ../info/emacs, produced by Makeinfo-1.55 from the
  2. input file emacs.texi.
  3.  
  4. 
  5. File: emacs,  Node: Intro,  Next: Glossary,  Prev: Copying,  Up: Top
  6.  
  7. Introduction
  8. ************
  9.  
  10.    You are reading about GNU Emacs, the GNU incarnation of the advanced,
  11. self-documenting, customizable, extensible real-time display editor
  12. Emacs.  (The `G' in `GNU' is not silent.)
  13.  
  14.    We say that Emacs is a "display" editor because normally the text
  15. being edited is visible on the screen and is updated automatically as
  16. you type your commands.  *Note Display: Screen.
  17.  
  18.    We call it a "real-time" editor because the display is updated very
  19. frequently, usually after each character or pair of characters you
  20. type.  This minimizes the amount of information you must keep in your
  21. head as you edit.  *Note Real-time: Basic.
  22.  
  23.    We call Emacs advanced because it provides facilities that go beyond
  24. simple insertion and deletion: controlling subprocesses; automatic
  25. indentation of programs; viewing two or more files at once; editing
  26. formatted text; and dealing in terms of characters, words, lines,
  27. sentences, paragraphs, and pages, as well as expressions and comments in
  28. several different programming languages.
  29.  
  30.    "Self-documenting" means that at any time you can type a special
  31. character, `Control-h', to find out what your options are.  You can
  32. also use it to find out what any command does, or to find all the
  33. commands that pertain to a topic.  *Note Help::.
  34.  
  35.    "Customizable" means that you can change the definitions of Emacs
  36. commands in little ways.  For example, if you use a programming
  37. language in which comments start with `<**' and end with `**>', you can
  38. tell the Emacs comment manipulation commands to use those strings
  39. (*note Comments::.).  Another sort of customization is rearrangement of
  40. the command set.  For example, if you prefer the four basic cursor
  41. motion commands (up, down, left and right) on keys in a diamond pattern
  42. on the keyboard, you can rebind the keys that way.  *Note
  43. Customization::.
  44.  
  45.    "Extensible" means that you can go beyond simple customization and
  46. write entirely new commands, programs in the Lisp language to be run by
  47. Emacs's own Lisp interpreter.  Emacs is an "on-line extensible" system,
  48. which means that it is divided into many functions that call each
  49. other, any of which can be redefined in the middle of an editing
  50. session.  Almost any part of Emacs can be replaced without making a
  51. separate copy of all of Emacs.  Most of the editing commands of Emacs
  52. are written in Lisp already; the few exceptions could have been written
  53. in Lisp but are written in C for efficiency.  Although only a programmer
  54. can write an extension, anybody can use it afterward.
  55.  
  56.    When run under the X Window System, Emacs provides its own menus and
  57. convenient bindings to mouse buttons.  But Emacs can provide many of the
  58. benefits of a window system on a text-only terminal.  For instance, you
  59. can look at or edit several files at once, move text between them, and
  60. edit files at the same time as you run shell commands.
  61.  
  62. 
  63. File: emacs,  Node: Screen,  Next: User Input,  Prev: Acknowledgments,  Up: Top
  64.  
  65. The Organization of the Screen
  66. ******************************
  67.  
  68.    On a text-only terminal, the Emacs display occupies the whole screen.
  69. On the X Window System, Emacs creates its own X windows to use.  We use
  70. the term "frame" to mean an entire text-only screen or an entire X
  71. window used by Emacs.  Emacs uses both kinds of frames in the same way
  72. to display your editing.  Emacs normally starts out with just one frame,
  73. but you can create additional frames if you wish.  *Note Frames::.
  74.  
  75.    When you start Emacs, the entire frame except for the last line is
  76. devoted to the text you are editing.  This area is called "window".
  77. The last line is a special "echo area" or "minibuffer window" where
  78. prompts appear and where you can enter responses.  You can subdivide
  79. the large text window horizontally or vertically into multiple text
  80. windows, each of which can be used for a different file (*note
  81. Windows::.).  In this manual, the word "window" always refers to the
  82. subdivisions of a frame within Emacs.
  83.  
  84.    The window that the cursor is in is the "selected window", in which
  85. editing takes place.  Most Emacs commands implicitly apply to the text
  86. in the selected window (though mouse commands generally operate on
  87. whatever window you click them in, whether selected or not).  The other
  88. windows display text for reference only, unless/until you select them.
  89. If you use multiple frames under the X Window System, then giving the
  90. input focus to a particular frame selects a window in that frame.
  91.  
  92.    Each window's last line is a "mode line" which describes what is
  93. going on in that window.  It appears in inverse video if the terminal
  94. supports that, and contains text that starts like `-----Emacs:
  95. SOMETHING'.  Its purpose is to indicate what buffer is being displayed
  96. above it in the window; what major and minor modes are in use; and
  97. whether the buffer contains unsaved changes.
  98.  
  99. * Menu:
  100.  
  101. * Point::    The place in the text where editing commands operate.
  102. * Echo Area::   Short messages appear at the bottom of the screen.
  103. * Mode Line::    Interpreting the mode line.
  104.  
  105. 
  106. File: emacs,  Node: Point,  Next: Echo Area,  Up: Screen
  107.  
  108. Point
  109. =====
  110.  
  111.    Within Emacs, the terminal's cursor shows the location at which
  112. editing commands will take effect.  This location is called "point".
  113. Many Emacs commands move point through the text, so that you can edit at
  114. different places in it.  You can also place point by clicking mouse
  115. button 1.
  116.  
  117.    While the cursor appears to point AT a character, you should think
  118. of point as BETWEEN two characters; it points BEFORE the character that
  119. appears under the cursor.  For example, if your text looks like `frob'
  120. with the cursor over the `b', then point is between the `o' and the
  121. `b'.  If you insert the character `!' at that position, the result is
  122. `fro!b', with point between the `!' and the `b'.  Thus, the cursor
  123. remains over the `b', as before.
  124.  
  125.    Sometimes people speak of "the cursor" when they mean "point", or
  126. speak of commands that move point as "cursor motion" commands.
  127.  
  128.    Terminals have only one cursor, and when output is in progress it
  129. must appear where the typing is being done.  This does not mean that
  130. point is moving.  It is only that Emacs has no way to show you the
  131. location of point except when the terminal is idle.
  132.  
  133.    If you are editing several files in Emacs, each in its own buffer,
  134. each buffer has its own point location.  A buffer that is not currently
  135. displayed remembers where point is in case you display it again later.
  136.  
  137.    When there are multiple windows in a frame, each window has its own
  138. point location.  The cursor shows the location of point in the selected
  139. window.  This also is how you can tell which window is selected.  If the
  140. same buffer appears in more than one window, each window has its own
  141. position for point in that buffer.
  142.  
  143.    When there are multiple frames, each frame can display one cursor.
  144. The cursor in the selected frame is solid; the cursor in other frames is
  145. a hollow box, and appears in the window that would be selected if you
  146. give the input focus to that frame.
  147.  
  148.    The term `point' comes from the character `.', which was the command
  149. in TECO (the language in which the original Emacs was written) for
  150. accessing the value now called `point'.
  151.  
  152. 
  153. File: emacs,  Node: Echo Area,  Next: Mode Line,  Prev: Point,  Up: Screen
  154.  
  155. The Echo Area
  156. =============
  157.  
  158.    The line at the bottom of the frame (below the mode line) is the
  159. "echo area".  It is used to display small amounts of text for several
  160. purposes.
  161.  
  162.    "Echoing" means displaying the characters that you type.  Outside
  163. Emacs, the operating system normally echoes all your input.  Emacs
  164. handles echoing differently.
  165.  
  166.    Single-character commands do not echo in Emacs, and multi-character
  167. commands echo only if you pause while typing them.  As soon as you pause
  168. for more than a second in the middle of a command, Emacs echoes all the
  169. characters of the command so far.  This is to "prompt" you for the rest
  170. of the command.  Once echoing has started, the rest of the command
  171. echoes immediately as you type it.  This behavior is designed to give
  172. confident users fast response, while giving hesitant users maximum
  173. feedback.  You can change this behavior by setting a variable (*note
  174. Display Vars::.).
  175.  
  176.    If a command cannot be executed, it may print an "error message" in
  177. the echo area.  Error messages are accompanied by a beep or by flashing
  178. the screen.  Also, any input you have typed ahead is thrown away when
  179. an error happens.
  180.  
  181.    Some commands print informative messages in the echo area.  These
  182. messages look much like error messages, but they are not announced with
  183. a beep and do not throw away input.  Sometimes the message tells you
  184. what the command has done, when this is not obvious from looking at the
  185. text being edited.  Sometimes the sole purpose of a command is to print
  186. a message giving you specific information--for example, `C-x =' prints
  187. a message describing the character position of point in the text and
  188. its current column in the window.  Commands that take a long time often
  189. display messages ending in `...' while they are working, and add `done'
  190. at the end when they are finished.
  191.  
  192.    Echo area informative messages appear also in a buffer named
  193. `*Messages*'.  If you miss a message that appears briefly on the
  194. screen, you can switch to the `*Messages*' buffer to see it again.
  195. Garbage collection messages are omitted from `*Messages*', and
  196. successive progress messages are often collapsed into one.
  197.  
  198.    The size of `*Messages*' is limited to a certain number of lines.
  199. The variable `message-log-max' specifies how many lines.  Once the
  200. buffer has that many lines, each line added at the end deletes one line
  201. from the beginning.  *Note Variables::, for how to set variables such as
  202. `message-log-max'.
  203.  
  204.    The echo area is also used to display the "minibuffer", a window that
  205. is used for reading arguments to commands, such as the name of a file
  206. to be edited.  When the minibuffer is in use, the echo area begins with
  207. a prompt string that usually ends with a colon; also, the cursor
  208. appears in that line because it is the selected window.  You can always
  209. get out of the minibuffer by typing `C-g'.  *Note Minibuffer::.
  210.  
  211. 
  212. File: emacs,  Node: Mode Line,  Prev: Echo Area,  Up: Screen
  213.  
  214. The Mode Line
  215. =============
  216.  
  217.    Each text window's last line is a "mode line" which describes what
  218. is going on in that window.  When there is only one text window, the
  219. mode line appears right above the echo area.  The mode line is in
  220. inverse video if the terminal supports that, it starts and ends with
  221. dashes, and it contains text like `Emacs: SOMETHING'.
  222.  
  223.    A few special editing modes, such as Dired and Rmail, display
  224. something else in place of `Emacs: SOMETHING'.  The rest of the mode
  225. line still has the usual meaning.
  226.  
  227.    Normally, the mode line looks like this:
  228.  
  229.      --CH-Emacs: BUF      (MAJOR MINOR)----POS------
  230.  
  231. This gives information about the buffer being displayed in the window:
  232. the buffer's name, what major and minor modes are in use, whether the
  233. buffer's text has been changed, and how far down the buffer you are
  234. currently looking.
  235.  
  236.    CH contains two stars `**' if the text in the buffer has been edited
  237. (the buffer is "modified"), or `--' if the buffer has not been edited.
  238. For a read-only buffer, it is `%*' if the buffer is modified, and `%%'
  239. otherwise.
  240.  
  241.    BUF is the name of the window's "buffer".  In most cases this is the
  242. same as the name of a file you are editing.  *Note Buffers::.
  243.  
  244.    The buffer displayed in the selected window (the window that the
  245. cursor is in) is also Emacs's selected buffer, the one that editing
  246. takes place in.  When we speak of what some command does to "the
  247. buffer", we are talking about the currently selected buffer.
  248.  
  249.    POS tells you whether there is additional text above the top of the
  250. window, or below the bottom.  If your buffer is small and it is all
  251. visible in the window, POS is `All'.  Otherwise, it is `Top' if you are
  252. looking at the beginning of the buffer, `Bot' if you are looking at the
  253. end of the buffer, or `NN%', where NN is the percentage of the buffer
  254. above the top of the window.
  255.  
  256.    MAJOR is the name of the "major mode" in effect in the buffer.  At
  257. any time, each buffer is in one and only one of the possible major
  258. modes.  The major modes available include Fundamental mode (the least
  259. specialized), Text mode, Lisp mode, C mode, Texinfo mode, and many
  260. others.  *Note Major Modes::, for details of how the modes differ and
  261. how to select one.
  262.  
  263.    Some major modes display additional information after the major mode
  264. name.  For example, Rmail buffers display the current message number and
  265. the total number of messages.  Compilation buffers and Shell buffers
  266. display the status of the subprocess.
  267.  
  268.    MINOR is a list of some of the "minor modes" that are turned on at
  269. the moment in the window's chosen buffer.  For example, `Fill' means
  270. that Auto Fill mode is on.  `Abbrev' means that Word Abbrev mode is on.
  271. `Ovwrt' means that Overwrite mode is on.  *Note Minor Modes::, for
  272. more information.  `Narrow' means that the buffer being displayed has
  273. editing restricted to only a portion of its text.  This is not really a
  274. minor mode, but is like one.  *Note Narrowing::.  `Def' means that a
  275. keyboard macro is being defined.  *Note Keyboard Macros::.
  276.  
  277.    In addition, if Emacs is currently inside a recursive editing level,
  278. square brackets (`[...]') appear around the parentheses that surround
  279. the modes.  If Emacs is in one recursive editing level within another,
  280. double square brackets appear, and so on.  Since recursive editing
  281. levels affect Emacs globally, not just one buffer, the square brackets
  282. appear in every window's mode line or not in any of them.  *Note
  283. Recursive Edit::.
  284.  
  285.    *Note Optional Mode Line::, for features that add other handy
  286. information to the mode line, such as the current line number of point,
  287. the current time, and whether new mail for you has arrived.
  288.  
  289. 
  290. File: emacs,  Node: User Input,  Next: Keys,  Prev: Screen,  Up: Top
  291.  
  292. Kinds of User Input
  293. ===================
  294.  
  295.    GNU Emacs uses an extension of the ASCII character set for keyboard
  296. input; it also accepts non-character input events including function
  297. keys and mouse button actions.
  298.  
  299.    ASCII consists of 128 character codes.  Some of these codes are
  300. assigned graphic symbols such as `a' and `='; the rest are control
  301. characters, such as `Control-a' (usually written `C-a' for short).
  302. `C-a' gets its name from the fact that you type it by holding down the
  303. CTRL key while pressing `a'.
  304.  
  305.    Some control characters have special names, and special keys you can
  306. type them with: for example, RET, TAB, LFD, DEL and ESC.  The space
  307. character is usually referred to below as SPC, even though strictly
  308. speaking it is a graphic character whose graphic happens to be blank.
  309.  
  310.    On ASCII terminals, there are only 32 possible control characters.
  311. These are the control variants of letters and `@[]\^_'.  In addition,
  312. the shift key is meaningless with control characters: `C-a' and `C-A'
  313. are the same character, and Emacs cannot distinguish them.
  314.  
  315.    But the Emacs character set has room for control variants of all
  316. characters, and for distinguishing between `C-a' and `C-A'.  X Windows
  317. makes it possible to enter all these characters.  For example, `C--'
  318. (that's Control-Minus) and `C-5' are meaningful Emacs commands under X.
  319.  
  320.    Another Emacs character set extension is that characters have
  321. additional modifier bits.  Only one modifier bit is commonly used; it is
  322. called Meta.  Every character has a Meta variant; examples include
  323. `Meta-a' (normally written `M-a', for short), `M-A' (not the same
  324. character as `M-a', but those two characters normally have the same
  325. meaning in Emacs), `M-RET', and `M-C-a'.  For reasons of tradition, we
  326. usually write `C-M-a' rather than `M-C-a'; logically speaking, the
  327. order in which the modifier keys CTRL and META are mentioned does not
  328. matter.
  329.  
  330.    Some terminals have a META key, and allow you to type Meta
  331. characters by holding this key down.  Thus, `Meta-a' is typed by
  332. holding down META and pressing `a'.  The META key works much like the
  333. SHIFT key.  Such a key is not always labeled META, however, as this
  334. function is often a special option for a key with some other primary
  335. purpose.
  336.  
  337.    If there is no META key, you can still type Meta characters using
  338. two-character sequences starting with ESC.  Thus, to enter `M-a', you
  339. could type `ESC a'.  To enter `C-M-a', you would type `ESC C-a'.  ESC
  340. is allowed on terminals with META keys, too, in case you have formed a
  341. habit of using it.
  342.  
  343.    X Windows provides several other modifier keys that can be applied to
  344. any input character.  These are called SUPER, HYPER and ALT.  We write
  345. `s-', `H-' and `A-' to say that a character uses these modifiers.
  346. Thus, `s-H-C-x' is short for `Super-Hyper-Control-x'.  Not all X
  347. terminals actually provide keys for these modifier flags--in fact, many
  348. terminals have a key labeled ALT which is really a META key.  The
  349. standard key bindings of Emacs do not include any characters with these
  350. modifiers.  But you can assign them meanings of your own by customizing
  351. Emacs.
  352.  
  353.    Keyboard input includes keyboard keys that are not characters at all:
  354. for example function keys and arrow keys.  Mouse buttons are also
  355. outside the gamut of characters.  You can modify these events with the
  356. modifier keys CONTROL, META, SUPER, HYPER and ALT like keyboard
  357. characters.
  358.  
  359.    Input characters and non-character inputs are collectively called
  360. "input events".  *Note Input Events: (elisp)Input Events, for more
  361. information.  If you are not doing Lisp programming, but simply want to
  362. redefine the meaning of some characters or non-character events, see
  363. *Note Customization::.
  364.  
  365.    ASCII terminals cannot really send anything to the computer except
  366. ASCII characters.  These terminals use a sequence of characters to
  367. represent each function key.  But that is invisible to the Emacs user,
  368. because the keyboard input routines recognize these special sequences
  369. and convert them to function key events before any other part of Emacs
  370. gets to see them.
  371.  
  372. 
  373. File: emacs,  Node: Keys,  Next: Commands,  Prev: User Input,  Up: Top
  374.  
  375. Keys
  376. ====
  377.  
  378.    A "key sequence" ("key", for short) is a sequence of input events
  379. that are meaningful as a unit--as "a single command." Some Emacs
  380. command sequences are just one character or one event; for example,
  381. just `C-f' is enough to move forward one character.  But Emacs also has
  382. commands that take two or more events to invoke.
  383.  
  384.    If a sequence of events is enough to invoke a command, it is a
  385. "complete key".  Examples of complete keys include `C-a', `X', RET,
  386. NEXT (a function key), DOWN (an arrow key), `C-x C-f' and `C-x 4 C-f'.
  387. If it isn't long enough to be complete, we call it a "prefix key".  The
  388. above examples show that `C-x' and `C-x 4' are prefix keys.  Every key
  389. sequence is either a complete key or a prefix key.
  390.  
  391.    Most single characters constitute complete keys in the standard Emacs
  392. command bindings.  A few of them are prefix keys.  A prefix key combines
  393. with the following input event to make a longer key sequence, which may
  394. itself be complete or a prefix.  For example, `C-x' is a prefix key, so
  395. `C-x' and the next input event combine to make a two-character key
  396. sequence.  Most of these key sequences are complete keys, including
  397. `C-x C-f' and `C-x b'.  A few, such as `C-x 4' and `C-x r', are
  398. themselves prefix keys that lead to three-character key sequences.
  399. There's no limit to the length of a key sequence, but in practice
  400. people rarely use sequences longer than four events.
  401.  
  402.    By contrast, you can't add more events onto a complete key.  For
  403. example, the two-character sequence `C-f C-k' is not a key, because the
  404. `C-f' is a complete key in itself.  It's impossible to give `C-f C-k'
  405. an independent meaning as a command.  `C-f C-k' is two key sequences,
  406. not one.
  407.  
  408.    All told, the prefix keys in Emacs are `C-c', `C-h', `C-x', `C-x
  409. C-a', `C-x n', `C-x r', `C-x v', `C-x 4', `C-x 5', `C-x 6', and ESC.
  410. But this is not cast in concrete; it is just a matter of Emacs's
  411. standard key bindings.  If you customize Emacs, you can make new prefix
  412. keys, or eliminate these.  *Note Key Bindings::.
  413.  
  414.    If you do make or eliminate prefix keys, that changes the set of
  415. possible key sequences.  For example, if you redefine `C-f' as a
  416. prefix, `C-f C-k' automatically becomes a key (complete, unless you
  417. define it too as a prefix).  Conversely, if you remove the prefix
  418. definition of `C-x 4', then `C-x 4 f' (or `C-x 4 ANYTHING') is no
  419. longer a key.
  420.  
  421.    Typing the help character (`C-h' or F1) after a prefix character
  422. displays a list of the commands starting with that prefix.  There are a
  423. few prefix characters for which `C-h' does not work--for historical
  424. reasons, they have other meanings for `C-h' which are not easy to
  425. change.  But F1 should work for all prefix characters.
  426.  
  427. 
  428. File: emacs,  Node: Commands,  Next: Text Characters,  Prev: Keys,  Up: Top
  429.  
  430. Keys and Commands
  431. =================
  432.  
  433.    This manual is full of passages that tell you what particular keys
  434. do.  But Emacs does not assign meanings to keys directly.  Instead,
  435. Emacs assigns meanings to named "commands", and then gives keys their
  436. meanings by "binding" them to commands.
  437.  
  438.    Every command has a name chosen by a programmer.  The name is usually
  439. made of a few English words separated by dashes; for example,
  440. `next-line' or `forward-word'.  A command also has a "function
  441. definition" which is a Lisp program; this is what makes the command do
  442. what it does.  In Emacs Lisp, a command is actually a special kind of
  443. Lisp function; one which specifies how to read arguments for it and
  444. call it interactively.  For more information on commands and functions,
  445. see *Note What Is a Function: (elisp)What Is a Function.  (The
  446. definition we use in this manual is simplified slightly.)
  447.  
  448.    The bindings between keys and commands are recorded in various tables
  449. called "keymaps".  *Note Keymaps::.
  450.  
  451.    When we say that "`C-n' moves down vertically one line" we are
  452. glossing over a distinction that is irrelevant in ordinary use but is
  453. vital in understanding how to customize Emacs.  It is the command
  454. `next-line' that is programmed to move down vertically.  `C-n' has this
  455. effect *because* it is bound to that command.  If you rebind `C-n' to
  456. the command `forward-word' then `C-n' will move forward by words
  457. instead.  Rebinding keys is a common method of customization.
  458.  
  459.    In the rest of this manual, we usually ignore this subtlety to keep
  460. things simple.  To give the information needed for customization, we
  461. state the name of the command which really does the work in parentheses
  462. after mentioning the key that runs it.  For example, we will say that
  463. "The command `C-n' (`next-line') moves point vertically down," meaning
  464. that `next-line' is a command that moves vertically down and `C-n' is a
  465. key that is standardly bound to it.
  466.  
  467.    While we are on the subject of information for customization only,
  468. it's a good time to tell you about "variables".  Often the description
  469. of a command will say, "To change this, set the variable `mumble-foo'."
  470. A variable is a name used to remember a value.  Most of the variables
  471. documented in this manual exist just to facilitate customization: some
  472. command or other part of Emacs examines the variable and behaves
  473. differently according to the value that you set.  Until you are
  474. interested in customizing, you can ignore the information about
  475. variables.  When you are ready to be interested, read the basic
  476. information on variables, and then the information on individual
  477. variables will make sense.  *Note Variables::.
  478.  
  479. 
  480. File: emacs,  Node: Text Characters,  Next: Entering Emacs,  Prev: Commands,  Up: Top
  481.  
  482. Character Set for Text
  483. ======================
  484.  
  485.    Emacs buffers use an 8-bit character set, because bytes have 8 bits.
  486. ASCII graphic characters in Emacs buffers are displayed with their
  487. graphics.  The newline character (which has the same character code as
  488. LFD) is displayed by starting a new line.  The tab character is
  489. displayed by moving to the next tab stop column (normally every 8
  490. columns).  Other control characters are displayed as a caret (`^')
  491. followed by the non-control version of the character; thus, `C-a' is
  492. displayed as `^A'.  Non-ASCII characters 128 and up are displayed with
  493. octal escape sequences; thus, character code 243 (octal) is displayed
  494. as `\243'.
  495.  
  496.    You can customize the display of these character codes (or ASCII
  497. characters) by creating a "display table".  *Note Display Tables:
  498. (elisp)Display Tables.  This is useful for editing files that use 8-bit
  499. European character sets.  *Note European Display::.
  500.  
  501. 
  502. File: emacs,  Node: Entering Emacs,  Next: Exiting,  Prev: Text Characters,  Up: Top
  503.  
  504. Entering and Exiting Emacs
  505. **************************
  506.  
  507.    The usual way to invoke Emacs is with the shell command `emacs'.
  508. Emacs clears the screen and then displays an initial help message and
  509. copyright notice.  Some operating systems discard all type-ahead when
  510. Emacs starts up; they give Emacs no way to prevent this.  Therefore, it
  511. is advisable to wait until Emacs clears the screen before typing your
  512. first editing command.
  513.  
  514.    If you run Emacs from a shell window under the X Window System, run
  515. it in the background with `emacs&'.  This way, Emacs does not tie up
  516. the shell window, so you can use that to run other shell commands while
  517. Emacs operates its own X windows.  You can begin typing Emacs commands
  518. as soon as you direct your keyboard input to the Emacs frame.
  519.  
  520.    When Emacs starts up, it makes a buffer named `*scratch*'.  That's
  521. the buffer you start out in.  The `*scratch*' buffer uses Lisp
  522. Interaction mode; you can use it to type Lisp expressions and evaluate
  523. them, or you can ignore that capability and simply doodle.  (You can
  524. specify a different major mode for this buffer by setting the variable
  525. `initial-major-mode' in your init file.  *Note Init File::.)
  526.  
  527.    It is possible to specify files to be visited, Lisp files to be
  528. loaded, and functions to be called, by giving Emacs arguments in the
  529. shell command line.  *Note Command Arguments::.  But we don't recommend
  530. doing this.  The feature exists mainly for compatibility with other
  531. editors.
  532.  
  533.    Many other editors are designed to be started afresh each time you
  534. want to edit.  You edit one file and then exit the editor.  The next
  535. time you want to edit either another file or the same one, you must run
  536. the editor again.  With these editors, it makes sense to use a command
  537. line argument to say which file to edit.
  538.  
  539.    But starting a new Emacs each time you want to edit a different file
  540. does not make sense.  For one thing, this would be annoyingly slow.  For
  541. another, this would fail to take advantage of Emacs's ability to visit
  542. more than one file in a single editing session.  And it would lose the
  543. other accumulated context, such as registers, undo history, and the mark
  544. ring.
  545.  
  546.    The recommended way to use GNU Emacs is to start it only once, just
  547. after you log in, and do all your editing in the same Emacs session.
  548. Each time you want to edit a different file, you visit it with the
  549. existing Emacs, which eventually comes to have many files in it ready
  550. for editing.  Usually you do not kill the Emacs until you are about to
  551. log out.  *Note Files::, for more information on visiting more than one
  552. file.
  553.  
  554. 
  555. File: emacs,  Node: Exiting,  Next: Basic,  Prev: Entering Emacs,  Up: Top
  556.  
  557. Exiting Emacs
  558. =============
  559.  
  560.    There are two commands for exiting Emacs because there are two kinds
  561. of exiting: "suspending" Emacs and "killing" Emacs.
  562.  
  563.    "Suspending" means stopping Emacs temporarily and returning control
  564. to its parent process (usually a shell), allowing you to resume editing
  565. later in the same Emacs job, with the same buffers, same kill ring,
  566. same undo history, and so on.  This is the usual way to exit.
  567.  
  568.    "Killing" Emacs means destroying the Emacs job.  You can run Emacs
  569. again later, but you will get a fresh Emacs; there is no way to resume
  570. the same editing session after it has been killed.
  571.  
  572. `C-z'
  573.      Suspend Emacs (`suspend-emacs') or iconify a frame
  574.      (`iconify-or-deiconify-frame').
  575.  
  576. `C-x C-c'
  577.      Kill Emacs (`save-buffers-kill-emacs').
  578.  
  579.    To suspend Emacs, type `C-z' (`suspend-emacs').  This takes you back
  580. to the shell from which you invoked Emacs.  You can resume Emacs with
  581. the shell command `%emacs' in most common shells.
  582.  
  583.    On systems that do not support suspending programs, `C-z' starts an
  584. inferior shell that communicates directly with the terminal.  Emacs
  585. waits until you exit the subshell.  (The way to do that is probably
  586. with `C-d' or `exit', but it depends on which shell you use.)  The only
  587. way on these systems to get back to the shell from which Emacs was run
  588. (to log out, for example) is to kill Emacs.
  589.  
  590.    Suspending also fails if you run Emacs under a shell that doesn't
  591. support suspending programs, even if the system itself does support it.
  592. In such a case, you can set the variable `cannot-suspend' to a
  593. non-`nil' value to force `C-z' to start an inferior shell.  (One might
  594. also describe Emacs's parent shell as "inferior" for failing to support
  595. job control properly, but that is a matter of taste.)
  596.  
  597.    When Emacs communicates directly with an X server and creates its own
  598. dedicated X windows, `C-z' has a different meaning.  Suspending an
  599. applications that uses its own X windows is not meaningful or useful.
  600. Instead, `C-z' runs the command `iconify-or-deiconify-frame', which
  601. temporarily closes up the selected Emacs frame (*note Frames::.).  The
  602. way to get back to a shell window is with the window manager.
  603.  
  604.    To kill Emacs, type `C-x C-c' (`save-buffers-kill-emacs').  A
  605. two-character key is used for this to make it harder to type.  This
  606. command first offers to save any modified file-visiting buffers.  If you
  607. do not save them all, it asks for reconfirmation with `yes' before
  608. killing Emacs, since any changes not saved will be lost forever.  Also,
  609. if any subprocesses are still running, `C-x C-c' asks for confirmation
  610. about them, since killing Emacs will kill the subprocesses immediately.
  611.  
  612.    There is no way to restart an Emacs session once you have killed it.
  613. You can, however, arrange for Emacs to record certain session
  614. information, such as which files are visited, when you kill it, so that
  615. the next time you restart Emacs it will try to visit the same files and
  616. so on.  *Note Saving Emacs Sessions::.
  617.  
  618.    The operating system usually listens for certain special characters
  619. whose meaning is to kill or suspend the program you are running.  This
  620. operating system feature is turned off while you are in Emacs.  The
  621. meanings of `C-z' and `C-x C-c' as keys in Emacs were inspired by the
  622. use of `C-z' and `C-c' on several operating systems as the characters
  623. for stopping or killing a program, but that is their only relationship
  624. with the operating system.  You can customize these keys to run any
  625. commands of your choice (*note Keymaps::.).
  626.  
  627. 
  628. File: emacs,  Node: Basic,  Next: Minibuffer,  Prev: Exiting,  Up: Top
  629.  
  630. Basic Editing Commands
  631. **********************
  632.  
  633.    We now give the basics of how to enter text, make corrections, and
  634. save the text in a file.  If this material is new to you, you might
  635. learn it more easily by running the Emacs learn-by-doing tutorial.  To
  636. use the tutorial, run Emacs and type `Control-h t'
  637. (`help-with-tutorial').
  638.  
  639.    To clear the screen and redisplay, type `C-l' (`recenter').
  640.  
  641. * Menu:
  642.  
  643. * Inserting Text::     Inserting text by simply typing it.
  644. * Moving Point::       How to move the cursor to the place where you want to
  645.                  change something.
  646. * Erasing::           Deleting and killing text.
  647. * Undo::               Undoing previous changes.
  648. * Files: Basic Files.  Visiting, creating, and saving files.
  649. * Help: Basic Help.    Asking what a character does.
  650. * Blank Lines::        Commands to make or delete blank lines.
  651. * Continuation Lines:: Lines too wide for the screen.
  652. * Position Info::      What page, line, row, or column is point on?
  653. * Arguments::           Numeric arguments for repeating a command.
  654.  
  655. 
  656. File: emacs,  Node: Inserting Text,  Next: Moving Point,  Up: Basic
  657.  
  658. Inserting Text
  659. ==============
  660.  
  661.    To insert printing characters into the text you are editing, just
  662. type them.  This inserts the characters you type into the buffer at the
  663. cursor (that is, at "point"; *note Point::.).  The cursor moves
  664. forward, and any text after the cursor moves forward too.  If the text
  665. in the buffer is `FOOBAR', with the cursor before the `B', then if you
  666. type `XX', you get `FOOXXBAR', with the cursor still before the `B'.
  667.  
  668.    To "delete" text you have just inserted, use DEL.  DEL deletes the
  669. character *before* the cursor (not the one that the cursor is on top of
  670. or under; that is the character AFTER the cursor).  The cursor and all
  671. characters after it move backwards.  Therefore, if you type a printing
  672. character and then type DEL, they cancel out.
  673.  
  674.    To end a line and start typing a new one, type RET.  This inserts a
  675. newline character in the buffer.  If point is in the middle of a line,
  676. RET splits the line.  Typing DEL when the cursor is at the beginning of
  677. a line deletes the preceding newline, thus joining the line with the
  678. preceding line.
  679.  
  680.    Emacs can split lines automatically when they become too long, if you
  681. turn on a special minor mode called "Auto Fill" mode.  *Note Filling::,
  682. for how to use Auto Fill mode.
  683.  
  684.    If you prefer to have text characters replace (overwrite) existing
  685. text rather than shove it to the right, you can enable Overwrite mode,
  686. a minor mode.  *Note Minor Modes::.
  687.  
  688.    Direct insertion works for printing characters and SPC, but other
  689. characters act as editing commands and do not insert themselves.  If you
  690. need to insert a control character or a character whose code is above
  691. 200 octal, you must "quote" it by typing the character `Control-q'
  692. (`quoted-insert') first.  (This character's name is normally written
  693. `C-q' for short.)  There are two ways to use `C-q':
  694.  
  695.    * `C-q' followed by any non-graphic character (even `C-g') inserts
  696.      that character.
  697.  
  698.    * `C-q' followed by three octal digits inserts the character with
  699.      the specified character code.
  700.  
  701. A numeric argument to `C-q' specifies how many copies of the quoted
  702. character should be inserted (*note Arguments::.).
  703.  
  704.    Customization information: DEL in most modes runs the command
  705. `delete-backward-char'; RET runs the command `newline', and
  706. self-inserting printing characters run the command `self-insert', which
  707. inserts whatever character was typed to invoke it.  Some major modes
  708. rebind DEL to other commands.
  709.  
  710. 
  711. File: emacs,  Node: Moving Point,  Next: Erasing,  Prev: Inserting Text,  Up: Basic
  712.  
  713. Changing the Location of Point
  714. ==============================
  715.  
  716.    To do more than insert characters, you have to know how to move point
  717. (*note Point::.).  The simplest way to do this is with arrow keys, or by
  718. clicking the left mouse button where you want to move to.
  719.  
  720.    There are also control and meta characters for cursor motion.  Some
  721. are equivalent to the arrow keys (these date back to the days before
  722. terminals had arrow keys, and are usable on terminals which don't have
  723. them).  Others do more sophisticated things.
  724.  
  725. `C-a'
  726.      Move to the beginning of the line (`beginning-of-line').
  727.  
  728. `C-e'
  729.      Move to the end of the line (`end-of-line').
  730.  
  731. `C-f'
  732.      Move forward one character (`forward-char').
  733.  
  734. `C-b'
  735.      Move backward one character (`backward-char').
  736.  
  737. `M-f'
  738.      Move forward one word (`forward-word').
  739.  
  740. `M-b'
  741.      Move backward one word (`backward-word').
  742.  
  743. `C-n'
  744.      Move down one line, vertically (`next-line').  This command
  745.      attempts to keep the horizontal position unchanged, so if you
  746.      start in the middle of one line, you end in the middle of the
  747.      next.  When on the last line of text, `C-n' creates a new line and
  748.      moves onto it.
  749.  
  750. `C-p'
  751.      Move up one line, vertically (`previous-line').
  752.  
  753. `M-r'
  754.      Move point to left margin, vertically centered in the window
  755.      (`move-to-window-line').  Text does not move on the screen.
  756.  
  757.      A numeric argument says which screen line to place point on.  It
  758.      counts screen lines down from the top of the window (zero for the
  759.      top line).  A negative argument counts lines from the bottom (-1
  760.      for the bottom line).
  761.  
  762. `M-<'
  763.      Move to the top of the buffer (`beginning-of-buffer').  With
  764.      numeric argument N, move to N/10 of the way from the top.  *Note
  765.      Arguments::, for more information on numeric arguments.
  766.  
  767. `M->'
  768.      Move to the end of the buffer (`end-of-buffer').
  769.  
  770. `M-x goto-char'
  771.      Read a number N and move point to character number N.  Position 1
  772.      is the beginning of the buffer.
  773.  
  774. `M-x goto-line'
  775.      Read a number N and move point to line number N.  Line 1 is the
  776.      beginning of the buffer.
  777.  
  778. `C-x C-n'
  779.      Use the current column of point as the "semipermanent goal column"
  780.      for `C-n' and `C-p' (`set-goal-column').  Henceforth, those
  781.      commands always move to this column in each line moved into, or as
  782.      close as possible given the contents of the line.  This goal
  783.      column remains in effect until canceled.
  784.  
  785. `C-u C-x C-n'
  786.      Cancel the goal column.  Henceforth, `C-n' and `C-p' once again
  787.      try to stick to a fixed horizontal position, as usual.
  788.  
  789.    If you set the variable `track-eol' to a non-`nil' value, then `C-n'
  790. and `C-p' when at the end of the starting line move to the end of
  791. another line.  Normally, `track-eol' is `nil'.  *Note Variables::, for
  792. how to set variables such as `track-eol'.
  793.  
  794.    Normally, `C-n' on the last line of a buffer appends a newline to
  795. it.  If the variable `next-line-add-newlines' is `nil', then `C-n' gets
  796. an error instead (like `C-p' on the first line).
  797.  
  798. 
  799. File: emacs,  Node: Erasing,  Next: Undo,  Prev: Moving Point,  Up: Basic
  800.  
  801. Erasing Text
  802. ============
  803.  
  804. `DEL'
  805.      Delete the character before point (`delete-backward-char').
  806.  
  807. `C-d'
  808.      Delete the character after point (`delete-char').
  809.  
  810. `C-k'
  811.      Kill to the end of the line (`kill-line').
  812.  
  813. `M-d'
  814.      Kill forward to the end of the next word (`kill-word').
  815.  
  816. `M-DEL'
  817.      Kill back to the beginning of the previous word
  818.      (`backward-kill-word').
  819.  
  820.    You already know about the DEL key which deletes the character
  821. before point (that is, before the cursor).  Another key, `Control-d'
  822. (`C-d' for short), deletes the character after point (that is, the
  823. character that the cursor is on).  This shifts the rest of the text on
  824. the line to the left.  If you type `C-d' at the end of a line, it joins
  825. together that line and the next line.
  826.  
  827.    To erase a larger amount of text, use the `C-k' key, which kills a
  828. line at a time.  If you type `C-k' at the beginning or middle of a
  829. line, it kills all the text up to the end of the line.  If you type
  830. `C-k' at the end of a line, it joins that line and the next line.
  831.  
  832.    *Note Killing::, for more flexible ways of killing text.
  833.  
  834. 
  835. File: emacs,  Node: Undo,  Next: Basic Files,  Prev: Erasing,  Up: Basic
  836.  
  837. Undoing Changes
  838. ===============
  839.  
  840.    You can undo all the recent changes in the buffer text, up to a
  841. certain point.  Each buffer records changes individually, and the undo
  842. command always applies to the current buffer.  Usually each editing
  843. command makes a separate entry in the undo records, but some commands
  844. such as `query-replace' make many entries, and very simple commands
  845. such as self-inserting characters are often grouped to make undoing less
  846. tedious.
  847.  
  848. `C-x u'
  849.      Undo one batch of changes--usually, one command worth (`undo').
  850.  
  851. `C-_'
  852.      The same.
  853.  
  854.    The command `C-x u' or `C-_' is how you undo.  The first time you
  855. give this command, it undoes the last change.  Point moves back to
  856. where it was before the command that made the change.
  857.  
  858.    Consecutive repetitions of `C-_' or `C-x u' undo earlier and earlier
  859. changes, back to the limit of the undo information available.  If all
  860. recorded changes have already been undone, the undo command prints an
  861. error message and does nothing.
  862.  
  863.    Any command other than an undo command breaks the sequence of undo
  864. commands.  Starting from that moment, the previous undo commands become
  865. ordinary changes that you can undo.  Thus, to redo changes you have
  866. undone, type `C-f' or any other command that will harmlessly break the
  867. sequence of undoing, then type more undo commands.
  868.  
  869.    If you notice that a buffer has been modified accidentally, the
  870. easiest way to recover is to type `C-_' repeatedly until the stars
  871. disappear from the front of the mode line.  At this time, all the
  872. modifications you made have been canceled.  Whenever an undo command
  873. makes the stars disappear from the mode line, it means that the buffer
  874. contents are the same as they were when the file was last read in or
  875. saved.
  876.  
  877.    If you do not remember whether you changed the buffer deliberately,
  878. type `C-_' once.  When you see the last change you made undone, you
  879. will see whether it was an intentional change.  If it was an accident,
  880. leave it undone.  If it was deliberate, redo the change as described
  881. above.
  882.  
  883.    Not all buffers record undo information.  Buffers whose names start
  884. with spaces don't; these buffers are used internally by Emacs and its
  885. extensions to hold text that users don't normally look at or edit.
  886.  
  887.    You cannot undo mere cursor motion; only changes in the buffer
  888. contents save undo information.  However, some cursor motion commands
  889. set the mark, so if you use these commands from time to time, you can
  890. move back to the neighborhoods you have moved through by popping the
  891. mark ring (*note Mark Ring::.).
  892.  
  893.    When the undo information for a buffer becomes too large, Emacs
  894. discards the oldest undo information from time to time (during garbage
  895. collection).  You can specify how much undo information to keep by
  896. setting two variables: `undo-limit' and `undo-strong-limit'.  Their
  897. values are expressed in units of bytes of space.
  898.  
  899.    The variable `undo-limit' sets a soft limit: Emacs keeps undo data
  900. for enough commands to reach this size, and perhaps exceed it, but does
  901. not keep data for any earlier commands beyond that.  Its default value
  902. is 20000.  The variable `undo-strong-limit' sets a stricter limit: the
  903. command which pushes the size past this amount is itself forgotten.
  904. Its default value is 30000.
  905.  
  906.    Regardless of the values of those variables, the most recent change
  907. is never discarded, so there is no danger that garbage collection
  908. occurring right after an unintentional large change might prevent you
  909. from undoing it.
  910.  
  911.    The reason the `undo' command has two keys, `C-x u' and `C-_', set
  912. up to run it is that it is worthy of a single-character key, but on
  913. some keyboards it is not obvious how to type `C-_'.  `C-x u' is an
  914. alternative you can type straightforwardly on any terminal.
  915.  
  916. 
  917. File: emacs,  Node: Basic Files,  Next: Basic Help,  Prev: Undo,  Up: Basic
  918.  
  919. Files
  920. =====
  921.  
  922.    The commands described above are sufficient for creating and altering
  923. text in an Emacs buffer; the more advanced Emacs commands just make
  924. things easier.  But to keep any text permanently you must put it in a
  925. "file".  Files are named units of text which are stored by the
  926. operating system for you to retrieve later by name.  To look at or use
  927. the contents of a file in any way, including editing the file with
  928. Emacs, you must specify the file name.
  929.  
  930.    Consider a file named `/usr/rms/foo.c'.  In Emacs, to begin editing
  931. this file, type
  932.  
  933.      C-x C-f /usr/rms/foo.c RET
  934.  
  935. Here the file name is given as an "argument" to the command `C-x C-f'
  936. (`find-file').  That command uses the "minibuffer" to read the
  937. argument, and you type RET to terminate the argument (*note
  938. Minibuffer::.).
  939.  
  940.    Emacs obeys the command by "visiting" the file: creating a buffer,
  941. copying the contents of the file into the buffer, and then displaying
  942. the buffer for you to edit.  If you alter the text, you can "save" the
  943. new text in the file by typing `C-x C-s' (`save-buffer').  This makes
  944. the changes permanent by copying the altered buffer contents back into
  945. the file `/usr/rms/foo.c'.  Until you save, the changes exist only
  946. inside Emacs, and the file `foo.c' is unaltered.
  947.  
  948.    To create a file, just visit the file with `C-x C-f' as if it
  949. already existed.  This creates an empty buffer in which you can insert
  950. the text you want to put in the file.  The file is actually created when
  951. you save this buffer with `C-x C-s'.
  952.  
  953.    Of course, there is a lot more to learn about using files.  *Note
  954. Files::.
  955.  
  956. 
  957. File: emacs,  Node: Basic Help,  Next: Blank Lines,  Prev: Basic Files,  Up: Basic
  958.  
  959. Help
  960. ====
  961.  
  962.    If you forget what a key does, you can find out with the Help
  963. character, which is `C-h' (or F1, which is an alias for `C-h').  Type
  964. `C-h k' followed by the key you want to know about; for example, `C-h k
  965. C-n' tells you all about what `C-n' does.  `C-h' is a prefix key; `C-h
  966. k' is just one of its subcommands (the command `describe-key').  The
  967. other subcommands of `C-h' provide different kinds of help.  Type `C-h'
  968. twice to get a description of all the help facilities.  *Note Help::.
  969.  
  970. 
  971. File: emacs,  Node: Blank Lines,  Next: Continuation Lines,  Prev: Basic Help,  Up: Basic
  972.  
  973. Blank Lines
  974. ===========
  975.  
  976.    Here are special commands and techniques for putting in and taking
  977. out blank lines.
  978.  
  979. `C-o'
  980.      Insert one or more blank lines after the cursor (`open-line').
  981.  
  982. `C-x C-o'
  983.      Delete all but one of many consecutive blank lines
  984.      (`delete-blank-lines').
  985.  
  986.    When you want to insert a new line of text before an existing line,
  987. you can do it by typing the new line of text, followed by RET.
  988. However, it may be easier to see what you are doing if you first make a
  989. blank line and then insert the desired text into it.  This is easy to do
  990. using the key `C-o' (`open-line'), which inserts a newline after point
  991. but leaves point in front of the newline.  After `C-o', type the text
  992. for the new line.  `C-o F O O' has the same effect as `F O O RET',
  993. except for the final location of point.
  994.  
  995.    You can make several blank lines by typing `C-o' several times, or
  996. by giving it a numeric argument to tell it how many blank lines to make.
  997. *Note Arguments::, for how.  If you have a fill prefix, then `C-o'
  998. command inserts the fill prefix on the new line, when you use it at the
  999. beginning of a line.  *Note Fill Prefix::.
  1000.  
  1001.    The easy way to get rid of extra blank lines is with the command
  1002. `C-x C-o' (`delete-blank-lines').  `C-x C-o' in a run of several blank
  1003. lines deletes all but one of them.  `C-x C-o' on a solitary blank line
  1004. deletes that blank line.  When point is on a nonblank line, `C-x C-o'
  1005. deletes any blank lines following that nonblank line.
  1006.  
  1007. 
  1008. File: emacs,  Node: Continuation Lines,  Next: Position Info,  Prev: Blank Lines,  Up: Basic
  1009.  
  1010. Continuation Lines
  1011. ==================
  1012.  
  1013.    If you add too many characters to one line without breaking it with
  1014. RET, the line will grow to occupy two (or more) lines on the screen,
  1015. with a `\' at the extreme right margin of all but the last of them.
  1016. The `\' says that the following screen line is not really a distinct
  1017. line in the text, but just the "continuation" of a line too long to fit
  1018. the screen.  Continuation is also called "line wrapping".
  1019.  
  1020.    Sometimes it is nice to have Emacs insert newlines automatically when
  1021. a line gets too long.  Continuation on the screen does not do that.  Use
  1022. Auto Fill mode (*note Filling::.) if that's what you want.
  1023.  
  1024.    As an alternative to continuation, Emacs can display long lines by
  1025. "truncation".  This means that all the characters that do not fit in
  1026. the width of the screen or window do not appear at all.  They remain in
  1027. the buffer, temporarily invisible.  `$' is used in the last column
  1028. instead of `\' to inform you that truncation is in effect.
  1029.  
  1030.    Truncation instead of continuation happens whenever horizontal
  1031. scrolling is in use, and optionally in all side-by-side windows (*note
  1032. Windows::.).  You can enable truncation for a particular buffer by
  1033. setting the variable `truncate-lines' to non-`nil' in that buffer.
  1034. (*Note Variables::.)  Altering the value of `truncate-lines' makes it
  1035. local to the current buffer; until that time, the default value is in
  1036. effect.  The default is initially `nil'.  *Note Locals::.
  1037.  
  1038.    *Note Display Vars::, for additional variables that affect how text
  1039. is displayed.
  1040.  
  1041.